﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using System.Web;
using YouHP.Atom;
using YouHP.Logic;


namespace YouHP.Pages.TreatmentHistory
{
    public class List : YouHP.Pages.PatientBasePage
    {

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
            if (ErrorCount > 0) return;

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected List<TreatmentHistoryInfo> TreatmentHistoryList;
        protected TreatmentInfo TrmData;
        protected int PageCount;
        protected int PageIndex;
        protected int PageSize = 10;
        protected string PagingString = "";
        protected int DataCount = 0;

        protected const int GraphHeight = 140;
        protected string GraphPath;

        protected TreatmentHistoryInfo CurTrmHistory;

        protected new void HandleCommon()
        {
            this.AddLocation("治疗记录", "/TreatmentHistory/Index.aspx");
            this.AddLocation("治疗详情", "");
            this.SetTitle("治疗详情");
        }

        protected new void HandlePost()
        {

        }

        protected new void HandleGet()
        {
            PageIndex = RequestTools.GetQueryInt("page", 1);
            int trmid = RequestTools.GetQueryInt("trmid", 0);

            if (trmid <= 0) {
                this.AddErrLine("无效的参数");
                return;
            }

            TrmData = TreatmentBLL.Instance.GetTreatmentInfo(trmid);
            if (TrmData.Id <= 0)
            {
                this.AddErrLine("无效的参数");
                return;
            }
            TreatmentHistoryLogic oHisLogic = new TreatmentHistoryLogic();
            //CurTrmHistory = oHisLogic.GetTreatmentsByPrId(PrData.Id);
            TreatmentHistoryList = oHisLogic.GetHistories(PrData.Id, trmid, PageSize, PageIndex, out PageCount);
            if (TreatmentHistoryList.Count() > 0 )
            {
                CurTrmHistory = TreatmentHistoryList[TreatmentHistoryList.Count - 1];
            }
            else
            {
                Redirect("/treatmenthistory/index.aspx");
            }
            
            //string query = HttpContext.Current.Request.Url.Query;
            //query = Utils.RemoveQueryItem(query, "page");

            //PagingString = this.GetPagingString(
            //    PageIndex,
            //    PageCount/PageSize+1,
            //    "/TreatmentHistory/List.aspx" + query, "page");

            //TempUrl = "/TreatmentHistory/TreatmentAjax.aspx?trmid=" + TrmData.Id;
            //GraphPath = GetUrl(TempUrl);

        }
    }
}